package com.hl.scriptDemo.util;

import org.springframework.stereotype.Component;

import java.util.concurrent.ConcurrentHashMap;

/**
 * groovy脚本缓存
 * @param <T> 缓存值的类型
 * @author hulei
 * @date 2024/2/19 10:06
 */
@Component
public class GroovyScriptCache<T> {
    private final ConcurrentHashMap<String, T> scriptCache = new ConcurrentHashMap<>();

    public void put(String key, T value) {
        if (key != null && value != null) {
            scriptCache.put(key, value);
        }
    }

    public T get(String key) {
        return scriptCache.get(key);
    }

    public boolean containsKey(String key) {
        return scriptCache.containsKey(key);
    }

    public void remove(String key) {
        scriptCache.remove(key);
    }

    public void clear() {
        scriptCache.clear();
    }
}
